<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
              <a-input :max-length="255"  disabled v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidNo">
              <a-input v-model="model.bidNo" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="经办人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <select-user-by-dep
                v-model="model.proposer"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="经办部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled />
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-col :span="8">
            <a-form-model-item label="关联投标档案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderId">
              <!--迭代11 投标档案弹窗-->
              <!-- <j-popup
                :disabled="formDisabled"
                v-model="model.tenderFinalCode"
                field="tenderFinalId"
                placeholder="请选择投标档案"
                dest-fields="tenderFinalId,prepareProjectId,id"
                org-fields ="tender_code,prepare_project_id,id"
                code="erp_omc_tender_final_model"
                @input="chooseTenderChange"
              /> -->
              <!-- 投标档案弹窗 -->
              <select-omc-project-tender-input :disabled="formDisabled" v-model="model.tenderId" @back="tenderFinalChange"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input :disabled="formDisabled" v-model="model.projectName" placeholder="请输入项目名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.undertaker"
                placeholder="请选择项目承接人"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.year"
                dictCode="yjgsnd"
                placeholder="请选择业绩归属年度"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item  label="项目地址" :labelCol="labelCol" :wrapperCol="wrapperCol" style="display: inline-block; width: 46%" prop="projectAddress">
              <AddressChoice :disabled="formDisabled" v-model="model.projectAddress" ></AddressChoice>
            </a-form-model-item>
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol"
              style="display: inline-block; width: 46%; margin-left: 45px;margin-top: 40px"
              prop="detailedAddress">
              <a-input :disabled="formDisabled" v-model="model.detailedAddress" placeholder="请输入项目详细地址"></a-input>
            </a-form-model-item>
            <!-- <a-form-model-item label="项目地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectAddress">

            </a-form-model-item> -->
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessTeam">
              <select-team-input
                :disabled="formDisabled"
                v-model="model.businessTeam"
                :tdlx="1"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="报名截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entriesEndDate">
              <a-date-picker
                show-time
                :disabled="formDisabled"
                v-model="entriesEndDate"
                @change="(date, dateStr) => { this.$set(this.model, 'entriesEndDate', dateStr) }"
                style="width: 100%"
                format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择报名截止时间"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投标截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderEndDate">
              <a-date-picker
                show-time
                :disabled="formDisabled"
                v-model="tenderEndDate"
                @change="(date, dateStr) => { this.$set(this.model, 'tenderEndDate', dateStr) }"
                style="width: 100%"
                :disabledDate="disabledDate"
                format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择投标截止时间"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
              <select-customer-input :disabled="formDisabled" v-model="model.ownerUnit" @change="ownerUnitChange"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业主联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerLinkman">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.ownerLinkman"
                :dictCode="customer_contacts"
                placeholder="请选择业主联系人"
                @change="contactsChange"
                :triggerChange="true"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业主联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerTel">
              <a-input :disabled="formDisabled" v-model="model.ownerTel" placeholder="请输入业主联系方式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标代理机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgent">
              <a-input :disabled="formDisabled" v-model="model.tenderAgent" placeholder="请输入招标代理机构"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标代理联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgentLinkman">
              <a-input :disabled="formDisabled" v-model="model.tenderAgentLinkman" placeholder="请输入招标代理联系人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标代理联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgentTel">
              <a-input :disabled="formDisabled" v-model="model.tenderAgentTel" placeholder="请输入招标代理联系方式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingMethod">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.biddingMethod"
                dictCode="bidding_method"
                placeholder="请选择招标方式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标控制价（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlPrice">
              <a-input-number
                :precision="2"
                :disabled="formDisabled"
                v-model="model.controlPrice"
                placeholder="请输入招标控制价"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <!--TASK#2243 4.投标文件审核：二审改为必填项、去掉难度系数 -->
          <!-- <a-col :span="8">
            <a-form-model-item label="难度系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="difficultyCoefficient">
              <a-input-number
                :disabled="formDisabled"
                v-model="model.difficultyCoefficient"
                placeholder="请输入难度系数"
                :min="0"
                :max="99999"
                style="width: 100%;"/>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="标书费（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidFee">
              <a-input-number
                :precision="2"
                :disabled="formDisabled"
                v-model="model.bidFee"
                placeholder="请输入标书费"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投标保证金（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderBond">
              <a-input-number
                :precision="2"
                :disabled="formDisabled"
                v-model="model.tenderBond"
                placeholder="请输入投标保证金"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <!--task#2119 4.在申请表单页面去掉投标保证金归还人和归还日期-->
          <!-- <a-col :span="8">
            <a-form-model-item label="投标保证金归还人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeReturn">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.feeReturn"/>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="投标保证金归还日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeReturnDate">
              <j-date
                :disabled="formDisabled"
                v-model="model.feeReturnDate"
                date-format="YYYY-MM-DD"
                style="width: 100%"
                placeholder="请选择投标保证金归还日期"/>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="会员平台费（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformFee">
              <a-input-number
                :precision="2"
                :disabled="formDisabled"
                v-model="model.platformFee"
                placeholder="请输入会员平台费"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目公示信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectPublicity">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.projectPublicity" rows="4" placeholder="请输入项目公示信息"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderContent">
              <a-textarea :disabled="formDisabled" v-model="model.tenderContent" rows="4" placeholder="请输入投标内容概要"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFile">
              <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.tenderFile"></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.tenderFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>

          <a-divider>投标任务信息</a-divider>
          <a-col :span="8">
            <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnitId">
              <j-dict-select-tag
                @input="chooseUnitChange"
                :disabled="formDisabled"
                type="list"
                v-model="model.tenderUnitId"
                :dictCode="unitDictCode"
                placeholder="请选择投标单位"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投标部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderDept">
              <j-select-depart :disabled="formDisabled" v-model="model.tenderDept" multi/>
            </a-form-model-item>
          </a-col>
          <!--task#2119 2.将投标金额和项目组成员去除；-->
          <!-- <a-col :span="8">
            <a-form-model-item label="投标金额（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAmount">
              <a-input :disabled="formDisabled" v-model="model.tenderAmount" placeholder="请输入投标金额"></a-input>
            </a-form-model-item>
          </a-col> -->
          <!--task#2119 3.印章类型去除。-->
          <!-- <a-col :span="8">
            <a-form-model-item label="印章类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sealType">
              <j-multi-select-tag
                :disabled="formDisabled"
                type="select"
                v-model="model.sealType"
                dictCode="yzlx_type"
                placeholder="请选择印章类型"/>
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="8">
            <a-form-model-item label="项目组成员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectMember">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.projectMember"
                multi="multi"/>
            </a-form-model-item>
          </a-col> -->

          <a-col :span="24">
            <div style="margin-bottom: 6px;margin-top: 6px">
              <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
            </div>
            <a-table
              ref="table"
              size="middle"
              rowKey="id"
              :loading="loading"
              :columns="columns"
              :pagination="false"
              :data-source="dataSource">
              <span slot="action" slot-scope="text, record">
                <template v-if="!formDisabled">
                  <a @click="handleEdit(record)">编辑</a>
                  <a-divider type="vertical"/>
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </template>
              </span>
            </a-table>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="标书一审人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidReview1">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.bidReview1"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="标书二审人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidReview2">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.bidReview2"/>
            </a-form-model-item>
          </a-col>
          <!--task#2119 1增加标书三审人，不必填-->
           <a-col :span="8">
            <a-form-model-item label="标书三审人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdReviewer">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.thirdReviewer"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="经营管理中心审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="omcAuditor">
              <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.omcAuditor"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="商务附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessFile">
              <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.businessFile"></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.businessFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="开标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidMethod">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.bidMethod"
                dictCode="tender_bid_method"
                placeholder="请选择开标方式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="文件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileType">
              <j-multi-select-tag
                :disabled="formDisabled"
                type="select"
                v-model="model.fileType"
                dictCode="tender_file_type"
                placeholder="请选择文件类型"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comments">
              <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.comments" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="审批意见附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comments">
              <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.twoReviewerFile"></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.twoReviewerFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col> -->
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button type="primary" @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form-model>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <erp-omc-tender-person-modal ref="personList" @ok="modalFormOk"></erp-omc-tender-person-modal>
    </j-form-container>
  </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import moment from 'moment';
import { mapGetters } from 'vuex';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import ViewFileModal from '@/views/scy/components/ViewFileModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin';
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil';
import ErpOmcTenderPersonForm from '@views/erp/omc/tenderfile/modules/ErpOmcTenderPersonForm';
import ErpOmcTenderPersonModal from '@views/erp/omc/tenderfile/modules/ErpOmcTenderPersonModal';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import SelectOmcProjectTenderInput from '@/views/scy/components/SelectOmcProjectTenderInput';

export default {
  name: 'ErpOmcTenderFileForm',
  mixins: [DisabledAuthFilterMixin, viewFile],
  components: {
    ErpOmcTenderPersonModal,
    ErpOmcTenderPersonForm,
    SelectUserByDep,
    SelectTeamInput,
    SelectCustomerInput,
    ViewFileModal,
    AddressChoice,
    SelectOmcProjectTenderInput
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      moment,
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      validatorRules: {
        bpmBizTitle: [
          { required: true, message: '请输入流程名称!' },
        ],
        bidNo: [
          { required: true, message: '请输入投标文件编号!' }
        ],
        createTime: [
          { required: true, message: '请选择创建日期!' }
        ],
        proposer: [
          { required: true, message: '请选择经办人!' }
        ],
        tenderId: [
          { required: true, message: '请选择投标申请编号!' }
        ],
        projectName: [
          { required: true, message: '请输入项目名称!' }
        ],
        undertaker: [
          { required: true, message: '请选择项目承接人!' }
        ],
        year: [
          { required: true, message: '请选择业绩归属年度!' }
        ],
        projectAddress: [
          { required: true, message: '请选择项目地址!' }
        ],
        detailedAddress:[
          { required: true, message: '请输入项目详细地址!' }
        ],
        businessTeam: [
          { required: true, message: '请选择经营团队!' }
        ],
        entriesEndDate: [
          { required: true, message: '请选择报名截止日期!' }
        ],
        tenderEndDate: [
          { required: true, message: '请选择投标截止日期!' }
        ],
        ownerUnit: [
          { required: true, message: '请选择业主单位!' }
        ],
        ownerLinkman: [
          { required: true, message: '请选择业主联系人!' }
        ],
        ownerTel: [
          { required: true, message: '请选择业主联系方式！' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        tenderAgent: [
          { required: true, message: '请输入招标代理机构' }
        ],
        tenderAgentLinkman: [
          { required: true, message: '请选择招标代理联系人!' }
        ],
        tenderAgentTel: [
          { required: true, message: '请选择招标代理联系方式！' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        biddingMethod: [
          { required: true, message: '请选择招标方式!' }
        ],
        controlPrice: [
          { required: true, message: '请输入招标控制价!' },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        difficultyCoefficient: [
          { required: false },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' }
        ],
        bidFee: [
          { required: true, message: '请输入标书费!' },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        tenderBond: [
          { required: true, message: '请输入投标保证金!' },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        platformFee: [
          { required: true, message: '请输入会员平台费!' },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        // task#2119 2.将投标金额和项目组成员去除；
        // tenderAmount: [
        //   { required: false },
        //   { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        // ],
        // task#2119 3.印章类型去除。
        // sealType: [
        //   { required: true, message: '请选择印章类别!' }
        // ],
        // projectMember: [
        //   { required: true, message: '请选择项目组成员!' }
        // ],
        bidMethod: [
          { required: true, message: '请选择开标方式!' }
        ],
        bidReview1: [
          { required: true, message: '请选择标书一审人!' }
        ],
        omcAuditor: [
          { required: true, message: '请选择经营管理中心审核人!' }
        ]
      },
      url: {
        add: '/api/erp/omc/tenderfile/erpOmcTenderFile/add',
        edit: '/api/erp/omc/tenderfile/erpOmcTenderFile/edit',
        queryById: '/api/erp/omc/tenderfile/erpOmcTenderFile/queryById',
        queryInfoAndUnit: '/api/erp/omc/tender/erpOmcTender/queryInfoAndUnit',
        queryTenderUnitDept: '/api/erp/omc/tender/erpOmcTenderUnit/queryTenderUnitDept',
        queryTenderPersonListByTenderFileId: '/api/erp/omc/tenderfile/erpOmcTenderPerson/queryTenderPersonListByTenderFileId',
        generatedFormNumber: '/api/erp/base/generatedFormNumber'
      },
      loading: false,
      columns: [
        {
          title: '投标编制人',
          align: 'center',
          dataIndex: 'tenderPerson',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['tenderPerson'], text + '')
            }
          }
        },
        {
          title: '负责部分',
          align: 'center',
          dataIndex: 'responsiblePart',
          width: '500px'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: '120px',
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      dataSource: [],
      dictOptions: {},
      customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0',
      unitDictCode: 'erp_company_files,file_name,id, del_flag=0 and audit_status=2',
      unitIds: '',
      entriesEndDate: undefined,
      tenderEndDate: undefined
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    this.initDictConfig();
  },
  methods: {
    handleAdd() {
      this.$refs.personList.add();
      this.$refs.personList.title = '新增';
      this.$refs.personList.disableSubmit = false;
    },
    handleEdit(record) {
      this.$refs.personList.edit(record);
      this.$refs.personList.title = '修改';
      this.$refs.personList.disableSubmit = false;
    },
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    initDictConfig() {
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderPerson', res.result)
        }
      })
    },
    // 业主单位
    ownerUnitChange() {
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      this.$set(this.model, 'ownerLinkman', undefined)
      this.$set(this.model, 'ownerTel', undefined)
    },
    // 业主联系人
    contactsChange(val) {
      this.$set(this.model, 'ownerLinkman', val)
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'ownerTel', data.lxfs)
        }
      })
    },
    chooseUnitChange(e) {
      if (e) {
        let params = { mainId: this.model.tenderId, tenderUnit: e };
        getAction(this.url.queryTenderUnitDept, params).then((res) => {
          if (res.success) {
            if (res.result) {
              this.model.tenderDept = res.result.tenderDept
              this.$forceUpdate()
            }
          }
        });
      }
    },
    chooseTenderChange(value,row,obj) {
      this.$set(this.model,'undertaker',obj.undertaker)
      this.$set(this.model,'year',obj.year)
      this.$set(this.model,'tenderId',obj.id)
      this.$set(this.model, 'projectName', obj.project_name)
      this.$set(this.model, 'projectType', obj.project_type)
      this.$set(this.model,'projectAddress',obj.project_address)
      this.$set(this.model,'detailedAddress',obj.detailed_address)
      this.$set(this.model,'ownerUnit',obj.owner_unit)
      this.$set(this.model,'ownerLinkman',obj.owner_linkman)
      this.$set(this.model,'businessTeam',obj.business_team)
      this.$set(this.model,'ownerTel',obj.owner_tel)
      this.$set(this.model,'biddingMethod',obj.bidding_method)
      this.$set(this.model,'tenderContent',obj.tender_content)
      this.$set(this.model,'tenderFile',obj.tender_file)
      this.$set(this.model,'controlPrice',obj.control_price)
      this.$set(this.model,'tenderBond',obj.tender_bond)
      this.$set(this.model,'entriesEndDate',obj.entries_end_date)
      this.entriesEndDate = obj.entries_end_date
      this.$set(this.model,'tenderEndDate',obj.tender_end_date)
      this.tenderEndDate = obj.tender_end_date
      this.unitIds = ''
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + res.result.ownerUnit + '\'';
      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId',{ id: obj.id }).then(res => {
        if(res.success){
          this.dataSource = res.result || []
        }
      })
      // if (e) {
      //   let params = { id: e };
      //   getAction(this.url.queryInfoAndUnit, params).then((res) => {
      //     if (res.success) {
      //       if (res.result) {
      //         this.unitIds = ''
      //         this.model.projectName = res.result.projectName
      //         this.model.projectType = res.result.projectType
      //         this.model.undertaker = res.result.undertaker
      //         this.model.year = res.result.year
      //         this.model.projectAddress = res.result.projectAddress
      //         this.model.detailedAddress = res.result.detailedAddress
      //         this.model.businessTeam = res.result.businessTeam
      //         this.model.entriesEndDate = res.result.entriesEndDate
      //         this.model.tenderEndDate = res.result.tenderEndDate
      //         this.entriesEndDate = res.result.entriesEndDate
      //         this.tenderEndDate = res.result.tenderEndDate
      //         this.model.ownerUnit = res.result.ownerUnit
      //         this.model.ownerLinkman = res.result.ownerLinkman
      //         this.model.ownerTel = res.result.ownerTel
      //         this.model.biddingMethod = res.result.biddingMethod
      //         this.model.controlPrice = res.result.controlPrice
      //         this.model.tenderBond = res.result.tenderBond
      //         this.model.tenderContent = res.result.tenderContent
      //         this.model.tenderFile = res.result.tenderFile
      //         this.model.detailedAddress = res.result.detailedAddress
      //         this.model.thirdReviewer = res.result.thirdReviewer
      //         this.model = Object.assign({}, this.model);
      //         // this.unitDictCode = this.unitDictCode + ' and id in (' + res.result.unitIds + ')'
      //         this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + res.result.ownerUnit + '\'';
      //       }
      //     }
      //   });
      // }
    },
    ...mapGetters(['userInfo']),
    add(value) {
      this.dataSource = []
      this.edit(this.modelDefault);
      this.model.proposer = value.loginUser.empId;
      this.model.proposerDeptId = this.userInfo().deptId;
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
      this.generatedFormNumber();
      this.entriesEndDate = undefined;
      this.tenderEndDate = undefined;
    },
    generatedFormNumber() {
      getAction(this.url.generatedFormNumber, { prefix: 'TBWJ', subSystemCode: '05' }).then(res => {
        if (res.success) {
          this.$set(this.model, 'bidNo', res.result)
        }
      })
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.entriesEndDate = this.model.entriesEndDate;
      this.tenderEndDate = this.model.tenderEndDate;
      if (this.model.id) {
        getAction(this.url.queryTenderPersonListByTenderFileId, { id: this.model.id }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
          }
        })
      }
      this.visible = true;
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          this.model.personList = this.dataSource;
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        } else {
          that.$emit('unButtonDisable');
        }
      })
    },
    disabledDate(currentDate) {
      return currentDate < moment(this.model.entriesEndDate).subtract('day')
    },
    // 关联投标档案编号修改带出数据
    tenderFinalChange(tenderFinal){
      this.$set(this.model,'bidOpeningData',tenderFinal.tenderEndDate)
      this.$set(this.model,'undertaker',tenderFinal.undertaker)
      this.$set(this.model,'year',tenderFinal.year)
      this.$set(this.model,'tenderFinalCode',tenderFinal.finalNo)
      this.$set(this.model, 'projectName', tenderFinal.projectName)
      this.$set(this.model, 'projectType', tenderFinal.projectType)
      this.$set(this.model,'projectAddress',tenderFinal.projectAddress)
      this.$set(this.model,'detailedAddress',tenderFinal.detailedAddress)
      this.$set(this.model,'ownerUnit',tenderFinal.ownerUnit)
      this.$set(this.model,'ownerLinkman',tenderFinal.ownerLinkman)
      this.$set(this.model,'businessTeam',tenderFinal.businessTeam)
      this.$set(this.model,'ownerTel',tenderFinal.ownerTel)
      this.$set(this.model,'biddingMethod',tenderFinal.biddingMethod)
      this.$set(this.model,'tenderContent',tenderFinal.tenderContent)
      this.$set(this.model,'tenderFile',tenderFinal.tenderFile)
      this.$set(this.model,'controlPrice',tenderFinal.controlPrice)
      // BUG#3276
      this.$set(this.model,'projectPublicity',tenderFinal.projectPublicity)

      //todo 迭代11 根据投标档案带出数据
      this.$set(this.model,'tenderUnit',tenderFinal.tenderUnit)

      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId',{ id: tenderFinal.id }).then(res => {
        if (res.success) {
          this.dataSource = res.result || []
        }
      })
    }
  }
}
</script>
<style scoped>
.ant-divider {
  font-size: 10px;
  font-weight: bold;
}

/*.ant-tabs{
  width: 850px;
}*/
</style>
